package com.geekchique.runningbuddy.controller;

import java.util.Calendar;
import java.util.GregorianCalendar;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.TextView;

import com.geekchique.runningbuddy.activity.MapOfJogs;
import com.geekchique.runningbuddy.activity.Today;
import com.geekchique.runningbuddy.model.ListOfJogs;
import com.geekchique.runningbuddy.util.DBHelperImpl;
import com.geekchique.runningbuddy.util.IDBHelper;
import com.geekchique.runningbuddy.view.JogEntryView;
import com.geekchique.runningbuddy.view.TodayView;

public class DayControllerImpl implements IDayController{

	@SuppressWarnings("unused")
	private TodayView todayView;
	@SuppressWarnings("unused")
	private JogEntryView jogEntryView;
	private IDBHelper dbHelper;
	private Activity context;
	private int MAPOFJOG = 3333;

	public DayControllerImpl(){
	}

	public DayControllerImpl(Activity today){
        this.dbHelper = new DBHelperImpl(today);
        this.context = today;
	}

	public void createTodayView(Today today, TextView miles, TextView timeRun, ListOfJogs allJogsRanToday) {
		this.todayView = new TodayView(today, miles, timeRun, allJogsRanToday);
	}

//	public void createLastJogEntryView(Activity today, TextView miles, TextView jogName_heading, TextView timeRun, long jogId) {
//		this.jogEntryView = new JogEntryView(today,  miles, jogName_heading, timeRun, jogId, this);
//	}

	public ListOfJogs getDayOfJogs(Integer day, Integer month, Integer year) {
		return (ListOfJogs) dbHelper.fetchAllJogEntries(day, month, year);
	}

	public ListOfJogs getTodaysJogs() {
		return  (ListOfJogs) dbHelper.fetchAllTodaysJogEntries();
	}

	public Cursor getCursorOfAllJogs() {
		return dbHelper.getCursorOfAllJogs();
	}

	public void setDBHelper(IDBHelper dbHelper){
		this.dbHelper = dbHelper;
	}

	public void openMapViewForJog(long jogStartTime) {
		Calendar cal = new GregorianCalendar();
		cal.setTimeInMillis(jogStartTime);

		Intent intent = new Intent(context, MapOfJogs.class);
		Bundle bundle = new Bundle();
		bundle.putInt("day", cal.get(Calendar.DAY_OF_MONTH));
		bundle.putInt("month", cal.get(Calendar.MONTH) + 1);
		bundle.putInt("year", cal.get(Calendar.YEAR));
		intent.putExtras(bundle);
		context.startSubActivity(intent, MAPOFJOG);
	}

}
